package com.qfedu.hotelssm.controller;

import com.qfedu.hotelssm.entity.User;
import com.qfedu.hotelssm.service.intf.UserService;
import com.qfedu.hotelssm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author truman
 * @date 2022/8/31
 * @description
 */
@RestController
@RequestMapping("/api/user/")
public class UserController {
    @Autowired
    private UserService service;

    /**
     * 新增
     */
    @PostMapping("save.do")
    public R save(User user) {
        return service.save(user);
    }
    /**
     * 删除
     */
    @GetMapping("delete.do")
    public R delete(int id) {
        return service.delete(id);
    }
    /**
     * 修改
     */
    @PostMapping("update.do")
    public R update(User user) {
        return service.update(user);
    }
    /**
     * 根据用户名查询
     */
    @GetMapping("byUsername.do")
    public R selectByName(String username) {
        return service.selectByName(username);
    }
    /**
     * 登录
     */
    @PostMapping("login.do")
    public R login(User user, HttpSession session) {
        return service.login(user, session);
    }
    /**
     * 退出登录
     */
    @GetMapping("outLogin.do")
    public R outLogin(HttpSession session) {
        session.invalidate();
        return R.ok();
    }
}
